package com.downbox.controller;

import com.downbox.dto.R;
import com.downbox.dto.SubmitReq;
import com.downbox.dto.SubmitResp;
import com.downbox.security.UserContext;
import com.downbox.service.ContributionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 投稿控制器
 */
@RestController
@RequestMapping("/submit")
@Tag(name = "投稿相关接口")
public class SubmitController {

    @Autowired
    private ContributionService contributionService;

    @PostMapping("/contribution")
    @Operation(summary = "提交投稿")
    public R<SubmitResp> submitContribution(@Valid @RequestBody SubmitReq req) {
        Long userId = UserContext.getUserId();
        SubmitResp resp = contributionService.submitContribution(userId, req);
        return R.success(resp);
    }
}